<?php
// -----------------------------------------------------------------------------
// include 
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if(!isset($_POST["description"])) {
    exit("需要传入有效的参数！");
}

// -----------------------------------------------------------------------------
// 时区设置
// -----------------------------------------------------------------------------

date_default_timezone_set($region);
$createTime = (string)time();
$lastEditTime = $createTime;
$sortNumber = $createTime;

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath; // 不加这行语句的话会报错，提示找不到对应路径
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

$arr = [];
$arr["createTime"] = $createTime;
$arr["lastEditTime"] = $lastEditTime;

$arr["sortNumber"] = $sortNumber;
$arr["description"] = $_POST["description"];
$arr["actionPlan"] = $_POST["actionPlan"];
$arr["motivation"] = $_POST["motivation"];
$arr["startDate"] = $_POST["startDate"];
$arr["endDate"] = $_POST["endDate"];

$arr["status"] = $_POST["status"];
$arr["achieveDate"] = $_POST["achieveDate"];
$arr["giveupDate"] = $_POST["giveupDate"];
$arr["giveupReason"] = $_POST["giveupReason"];

// -----------------------------------------------------------------------------

try {
    $db->insertIntoGoals($arr);
    echo "创建成功！";
} catch (Exception $e) {
    echo "出错啦！详情如下：";
    echo "<br />";
    echo $e->getMessage();
}
